

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>aiy.cloudspeech &mdash; AIY Projects 2018-11-16 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
        <script src="_static/jquery.js"></script>
        <script src="_static/underscore.js"></script>
        <script src="_static/doctools.js"></script>
        <script src="_static/language_data.js"></script>
    
    <script type="text/javascript" src="_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="_static/custom.css" type="text/css" />
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="aiy.voice.audio" href="aiy.voice.audio.html" />
    <link rel="prev" title="aiy.assistant" href="aiy.assistant.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="index.html" class="icon icon-home"> AIY Projects
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Common APIs</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="aiy.board.html">aiy.board</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.leds.html">aiy.leds</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.pins.html">aiy.pins</a></li>
</ul>
<p class="caption"><span class="caption-text">Vision Kit APIs</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="vision.html">Overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.toneplayer.html">aiy.toneplayer</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.trackplayer.html">aiy.trackplayer</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.vision.annotator.html">aiy.vision.annotator</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.vision.inference.html">aiy.vision.inference</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.vision.models.html">aiy.vision.models</a></li>
</ul>
<p class="caption"><span class="caption-text">Voice Kit APIs</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="voice.html">Overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.assistant.html">aiy.assistant</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">aiy.cloudspeech</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.voice.audio.html">aiy.voice.audio</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.voice.tts.html">aiy.voice.tts</a></li>
</ul>
<p class="caption"><span class="caption-text">Other docs</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://github.com/google/aiyprojects-raspbian">Source code (GitHub)</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/google/aiyprojects-raspbian/blob/aiyprojects/CHANGES.md">Change log (GitHub)</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/google/aiyprojects-raspbian/blob/aiyprojects/HACKING.md">Software setup (GitHub)</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/google/aiyprojects-raspbian/blob/aiyprojects/CONTRIBUTING.md">Contribution guide (GitHub)</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="index.html">AIY Projects</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="index.html">Docs</a> &raquo;</li>
        
      <li>aiy.cloudspeech</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="_sources/aiy.cloudspeech.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="module-aiy.cloudspeech">
<span id="aiy-cloudspeech"></span><h1>aiy.cloudspeech<a class="headerlink" href="#module-aiy.cloudspeech" title="Permalink to this headline">¶</a></h1>
<p>APIs that simplify interaction with the <a class="reference external" href="https://cloud.google.com/speech-to-text/docs/">Google Cloud Speech-to-Text service</a> so you can convert voice commands into actions.
To use this service, you must have a Google Cloud account and a corresponding credentials file.
For more information, see <a class="reference external" href="https://aiyprojects.withgoogle.com/voice/#makers-guide--custom-voice-user-interface">these setup instructions</a>.</p>
<p>For an example, see <a class="reference external" href="https://github.com/google/aiyprojects-raspbian/tree/aiyprojects/src/examples/voice/cloudspeech_demo.py">src/examples/voice/cloudspeech_demo.py</a>.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>These APIs are designed for the Voice Kit, but have no dependency on the Voice
HAT/Bonnet specifically. However, they do require some type of sound card
attached to the Raspberry Pi that can be detected by the ALSA subsystem.</p>
</div>
<dl class="class">
<dt id="aiy.cloudspeech.CloudSpeechClient">
<em class="property">class </em><code class="sig-prename descclassname">aiy.cloudspeech.</code><code class="sig-name descname">CloudSpeechClient</code><span class="sig-paren">(</span><em class="sig-param">service_accout_file=None</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.cloudspeech.CloudSpeechClient" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a></p>
<p>A simplified version of the Google Cloud <code class="docutils literal notranslate"><span class="pre">SpeechClient</span></code> class.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>service_accout_file</strong> – Absolute path to your JSON account credentials file.
If None, it looks for the file at <code class="docutils literal notranslate"><span class="pre">~/cloud_speech.json</span></code>.
To get a credentials file, <a class="reference external" href="https://aiyprojects.withgoogle.com/voice/#makers-guide--custom-voice-user-interface">these setup instructions</a>.</p>
</dd>
</dl>
<dl class="method">
<dt id="aiy.cloudspeech.CloudSpeechClient.recognize">
<code class="sig-name descname">recognize</code><span class="sig-paren">(</span><em class="sig-param">language_code='en-US'</em>, <em class="sig-param">hint_phrases=None</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.cloudspeech.CloudSpeechClient.recognize" title="Permalink to this definition">¶</a></dt>
<dd><p>Performs speech-to-text for a single utterance using the default ALSA soundcard driver.
Once it detects the user is done speaking, it stops listening and delivers the top
result as text.</p>
<p>By default, this method calls <a class="reference internal" href="#aiy.cloudspeech.CloudSpeechClient.start_listening" title="aiy.cloudspeech.CloudSpeechClient.start_listening"><code class="xref py py-meth docutils literal notranslate"><span class="pre">start_listening()</span></code></a> and <a class="reference internal" href="#aiy.cloudspeech.CloudSpeechClient.stop_listening" title="aiy.cloudspeech.CloudSpeechClient.stop_listening"><code class="xref py py-meth docutils literal notranslate"><span class="pre">stop_listening()</span></code></a> as the
recording begins and ends, respectively.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>language_code</strong> – Language expected from the user, in IETF BCP 47 syntax (default is
“en-US”). See the <a class="reference external" href="https://cloud.google.com/speech-to-text/docs/languages">list of Cloud’s supported languages</a>.</p></li>
<li><p><strong>hint_phrase</strong> – A list of strings containing words and phrases that may be expected from
the user. These hints help the speech recognizer identify them in the dialog and
improve the accuracy of your results.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>The text transcription of the user’s dialog.</p>
</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="aiy.cloudspeech.CloudSpeechClient.recognize_bytes">
<code class="sig-name descname">recognize_bytes</code><span class="sig-paren">(</span><em class="sig-param">data</em>, <em class="sig-param">language_code='en-US'</em>, <em class="sig-param">hint_phrases=None</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.cloudspeech.CloudSpeechClient.recognize_bytes" title="Permalink to this definition">¶</a></dt>
<dd><p>Performs speech-to-text for a single utterance using the given data source.
Once it detects the user is done speaking, it stops listening and delivers the top
result as text.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> – The audio data source. Must be encoded with a sample rate of 16000Hz.</p></li>
<li><p><strong>language_code</strong> – Language expected from the user, in IETF BCP 47 syntax (default is
“en-US”). See the <a class="reference external" href="https://cloud.google.com/speech-to-text/docs/languages">list of Cloud’s supported languages</a>.</p></li>
<li><p><strong>hint_phrase</strong> – A list of strings containing words and phrases that may be expected from
the user. These hints help the speech recognizer identify them in the dialog and
improve the accuracy of your results.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>The text transcription of the user’s dialog.</p>
</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="aiy.cloudspeech.CloudSpeechClient.start_listening">
<code class="sig-name descname">start_listening</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#aiy.cloudspeech.CloudSpeechClient.start_listening" title="Permalink to this definition">¶</a></dt>
<dd><p>By default, this simply prints “Start listening” to the log.</p>
<p>This method is provided as a convenience method that you can override in a derived class to
do something else that indicates the status to the user, such as change the LED state.</p>
<p>Called by <a class="reference internal" href="#aiy.cloudspeech.CloudSpeechClient.recognize" title="aiy.cloudspeech.CloudSpeechClient.recognize"><code class="xref py py-meth docutils literal notranslate"><span class="pre">recognize()</span></code></a> when recording begins.</p>
</dd></dl>

<dl class="method">
<dt id="aiy.cloudspeech.CloudSpeechClient.stop_listening">
<code class="sig-name descname">stop_listening</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#aiy.cloudspeech.CloudSpeechClient.stop_listening" title="Permalink to this definition">¶</a></dt>
<dd><p>By default, this simply prints “Stop listening” to the log.</p>
<p>This method is provided as a convenience method that you can override in a derived class to
do something else that indicates the status to the user, such as change the LED state.</p>
<p>Called by <a class="reference internal" href="#aiy.cloudspeech.CloudSpeechClient.recognize" title="aiy.cloudspeech.CloudSpeechClient.recognize"><code class="xref py py-meth docutils literal notranslate"><span class="pre">recognize()</span></code></a> when recording ends.</p>
</dd></dl>

</dd></dl>

</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="aiy.voice.audio.html" class="btn btn-neutral float-right" title="aiy.voice.audio" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="aiy.assistant.html" class="btn btn-neutral float-left" title="aiy.assistant" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2018, Google LLC

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>